m = input()
l = [ ]
g = [ ]
for i in range(1,4+1):
    l+=[int(m[:i])]
for i in range(2,4+1):
    l+=[int(m[1:i])]
for i in range(3,4+1):
    l+=[int(m[2:i])]
for a in l:
    k=[ ]
    for i in range(2,int(int(a)**0.5)+1):
        if int(a)%i==0 or int(a)==1:
            k+=[1]
    if len(k)>0:g+=[0]
    else: g+=[int(a)]
print(max(g))
